package com.luckku.boot.controller;


import com.luckku.boot.common.api.ApiResult;
import com.luckku.boot.entity.Notice;
import com.luckku.boot.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Luckku
 * @since 2022-10-09
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;
    /**
     * /notice/post
     * 发布公告
     *
     * @param notice Notice
     * @return ApiResult<Notice>
     */
    @PostMapping(value = "/addNotice")
    public ApiResult<Notice> postNotice(@Valid @RequestBody Notice notice) {
        noticeService.save(notice);
        return ApiResult.success(notice);
    }

    /**
     * /user/getAllNotices
     * 获取所有公告
     *
     * @return ApiResult<List<Notice>>
     */
    @GetMapping(value = "/getAllNotices")
    public ApiResult<List<Notice>> getAllNotices() {
        List<Notice> noticeList = noticeService.list();
        return ApiResult.success(noticeList);
    }

    /**
     * /user/getNoticesById
     * 根据ID获取公告
     *
     * @return ApiResult<Notice>
     */
    @GetMapping(value = "/getNoticesById")
    public ApiResult<Notice> getNoticesById(@RequestParam(value = "noticeId") String noticeId) {
        Notice noticeList = noticeService.getById(noticeId);
        return ApiResult.success(noticeList);
    }


}

